package com.social.controller;


import com.social.pojo.PageBean;
import com.social.pojo.Result;
import com.social.pojo.SysRole;
import com.social.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统角色Controller控制器
 * @author zhm
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/listAll")
//    @PreAuthorize("hasAuthority('system:role:query')")
    public Result listAll(){
        return sysRoleService.listAll();
    }

    @PostMapping("/list")
    public Result list(@Valid @RequestBody PageBean pageBean){
        return sysRoleService.getAll(pageBean);
    }

    @Transactional
    @PostMapping("/delete")
    public Result delete(@Valid @RequestBody Long[] ids){
        return sysRoleService.deleteById(ids);
    }

    @PutMapping("/save")
    public Result add(@Valid @RequestBody SysRole sysRole){
        return sysRoleService.add(sysRole);
    }

    @PutMapping("/update")
    public Result update(@Valid @RequestParam SysRole sysRole){
        return sysRoleService.update(sysRole);
    }

    @Transactional
    @PostMapping("/grantMenu/{roleId}")
    public Result grantMenu(@PathVariable("roleId") Long roleId, @RequestBody Long[] menuIds){
        return sysRoleService.grantMenu(roleId, menuIds);
    }

}